package com.netease.pris.activity;

import android.app.ProgressDialog;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.preference.CheckBoxPreference;
import android.preference.Preference;
import android.preference.Preference.OnPreferenceChangeListener;
import android.preference.PreferenceGroup;
import com.netease.b.a.d;
import com.netease.framework.PreferenceActivityEx;
import com.netease.pris.app.PrisApp;
import com.netease.pris.atom.u;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.LinkedList;

public class OfflineDownloadMgrActivity extends PreferenceActivityEx
  implements Preference.OnPreferenceChangeListener
{
  private static final String a = "offline_donwload_mgr_setting_select_all_source";
  private static final String b = "offline_donwload_mgr_setting_source_list";
  private static final String c = "OfflineDownloadMgrActivity";
  private static final int d;
  private CheckBoxPreference e;
  private PreferenceGroup f;
  private ArrayList g = new ArrayList(2);
  private ArrayList h = new ArrayList(2);
  private ProgressDialog i = null;
  private Handler j = new fv(this);

  private void a()
  {
    ArrayList localArrayList = new ArrayList(2);
    Iterator localIterator = this.h.iterator();
    while (localIterator.hasNext())
    {
      df localdf = (df)localIterator.next();
      if (!a(localdf, this.g))
        continue;
      String str = df.a(localdf);
      if (!df.b(localdf));
      for (boolean bool = true; ; bool = false)
      {
        localArrayList.add(new dd(this, str, bool));
        break;
      }
    }
    PrisApp.a().a(localArrayList);
  }

  public static void a(Context paramContext)
  {
    paramContext.startActivity(new Intent(paramContext, OfflineDownloadMgrActivity.class));
  }

  private void a(String paramString, boolean paramBoolean)
  {
    if (this.g == null)
      return;
    while (true)
    {
      Iterator localIterator = this.g.iterator();
      if (!localIterator.hasNext())
        continue;
      df localdf = (df)localIterator.next();
      if (!df.a(localdf).equals(paramString))
        break;
      df.a(localdf, paramBoolean);
    }
  }

  private void a(boolean paramBoolean)
  {
    if (this.g == null);
    while (true)
    {
      return;
      Iterator localIterator = this.g.iterator();
      while (localIterator.hasNext())
        df.a((df)localIterator.next(), paramBoolean);
    }
  }

  private boolean a(df paramdf, ArrayList paramArrayList)
  {
    int k = 0;
    if ((paramdf == null) || (paramArrayList == null));
    df localdf;
    do
    {
      Iterator localIterator;
      while (!localIterator.hasNext())
      {
        return k;
        localIterator = paramArrayList.iterator();
      }
      localdf = (df)localIterator.next();
    }
    while (!df.a(paramdf).equals(df.a(localdf)));
    if (df.b(paramdf) != df.b(localdf));
    for (int m = 1; ; m = 0)
    {
      k = m;
      break;
    }
  }

  public static Intent b(Context paramContext)
  {
    return new Intent(paramContext, OfflineDownloadMgrActivity.class);
  }

  private void b()
  {
    e();
    c();
  }

  private void b(boolean paramBoolean)
  {
    for (int k = 0; k < this.f.getPreferenceCount(); k++)
    {
      Preference localPreference = this.f.getPreference(k);
      if (localPreference.getKey().equals("offline_donwload_mgr_setting_select_all_source"))
        continue;
      ((CheckBoxPreference)localPreference).setChecked(paramBoolean);
      this.i.setProgress(k);
    }
    if (paramBoolean)
    {
      ArrayList localArrayList = i();
      com.netease.pris.c.c.a(this, d.h().c(), localArrayList);
    }
    while (true)
    {
      a(paramBoolean);
      k();
      return;
      com.netease.pris.c.c.d(this, d.h().c());
    }
  }

  private void c()
  {
    boolean bool1 = false;
    this.f.removeAll();
    this.f.addPreference(this.e);
    boolean bool2 = true;
    Iterator localIterator = this.g.iterator();
    while (localIterator.hasNext())
    {
      df localdf = (df)localIterator.next();
      CheckBoxPreference localCheckBoxPreference = new CheckBoxPreference(this);
      localCheckBoxPreference.setTitle(df.c(localdf));
      localCheckBoxPreference.setPersistent(false);
      if ((bool2) && (!df.b(localdf)))
        bool2 = false;
      localCheckBoxPreference.setKey(df.a(localdf));
      localCheckBoxPreference.setOnPreferenceChangeListener(this);
      localCheckBoxPreference.setChecked(df.b(localdf));
      this.f.addPreference(localCheckBoxPreference);
    }
    if (this.g.size() == 0);
    while (true)
    {
      this.e.setChecked(bool1);
      return;
      bool1 = bool2;
    }
  }

  private void e()
  {
    this.g.clear();
    LinkedList localLinkedList = com.netease.pris.c.c.a(this, d.h().c(), false);
    if (localLinkedList == null);
    while (true)
    {
      return;
      Iterator localIterator = localLinkedList.iterator();
      while (localIterator.hasNext())
      {
        u localu = (u)localIterator.next();
        String str1 = localu.U();
        String str2 = localu.V();
        boolean bool = com.netease.pris.c.c.c(this, d.h().c(), localu.V());
        this.g.add(new df(this, str1, str2, bool));
        this.h.add(new df(this, str1, str2, bool));
      }
    }
  }

  private void g()
  {
    this.e = ((CheckBoxPreference)findPreference("offline_donwload_mgr_setting_select_all_source"));
    this.e.setOnPreferenceChangeListener(this);
    this.f = ((PreferenceGroup)findPreference("offline_donwload_mgr_setting_source_list"));
  }

  private boolean h()
  {
    int k;
    if (this.g == null)
      k = 0;
    while (true)
    {
      return k;
      Iterator localIterator = this.g.iterator();
      while (true)
        if (localIterator.hasNext())
        {
          if (df.b((df)localIterator.next()))
            continue;
          k = 0;
          break;
        }
      k = 1;
    }
  }

  private ArrayList i()
  {
    if (this.g == null)
      throw new RuntimeException("mSource is null");
    ArrayList localArrayList = new ArrayList();
    Iterator localIterator = this.g.iterator();
    while (localIterator.hasNext())
    {
      df localdf = (df)localIterator.next();
      if (df.b(localdf))
        continue;
      localArrayList.add(df.a(localdf));
    }
    return localArrayList;
  }

  private void j()
  {
    this.i = ProgressDialog.show(this, null, getText(2131362289), true, true);
    this.i.setIndeterminate(false);
    this.i.setMax(this.f.getPreferenceCount());
  }

  private void k()
  {
    if (this.i != null)
    {
      this.i.dismiss();
      this.i = null;
    }
  }

  public void onCreate(Bundle paramBundle)
  {
    super.onCreate(paramBundle);
    addPreferencesFromResource(2131034113);
    g();
    b();
  }

  protected void onDestroy()
  {
    a();
    super.onDestroy();
    if (this.g != null)
    {
      this.g.clear();
      this.g = null;
    }
    if (this.h != null)
    {
      this.h.clear();
      this.h = null;
    }
    if (this.f != null)
    {
      this.f.removeAll();
      this.f = null;
    }
    System.gc();
  }

  public boolean onPreferenceChange(Preference paramPreference, Object paramObject)
  {
    int k;
    if (paramPreference.getKey().equals("offline_donwload_mgr_setting_select_all_source"))
    {
      j();
      boolean bool2 = ((Boolean)paramObject).booleanValue();
      this.j.postDelayed(new fu(this, bool2), 300L);
      k = 1;
      return k;
    }
    String str1 = paramPreference.getKey();
    boolean bool1 = ((Boolean)paramObject).booleanValue();
    ((CheckBoxPreference)paramPreference).setChecked(bool1);
    com.netease.pris.c.c.a(this, d.h().c(), str1, bool1);
    String str2 = ((CheckBoxPreference)paramPreference).getTitle().toString();
    if (bool1)
    {
      com.netease.pris.d.c.a(f(), 651, str2);
      label117: a(str1, bool1);
      if (bool1)
        break label158;
      this.e.setChecked(false);
    }
    while (true)
    {
      k = 0;
      break;
      com.netease.pris.d.c.a(f(), 652, str2);
      break label117;
      label158: this.e.setChecked(h());
    }
  }
}

/* Location:           D:\android\hack\dex2jar-0.0.9.8\classes_dex2jar.jar
 * Qualified Name:     com.netease.pris.activity.OfflineDownloadMgrActivity
 * JD-Core Version:    0.6.0
 */